﻿#region  文件信息

// ---------------------------------------------------------------------------------------
// <copyright file="Substring.cs" company="">
// 作者：李帅伦
// </copyright>
// <summary>
// 类型简介：
// 类型详细：Substring.cs
// 创建时间：2014-12-16 9:20
// 修改时间：2014-09-29 17:08
// </summary>
// ---------------------------------------------------------------------------------------

#endregion

using System;

namespace WebCommon.Com
{
    #region

    

    #endregion

    public class Substring
    {
        #region Constructors and Destructors

        public Substring(string str)
        {
            this.Str = str;
            this.Bend = true;
            this.Bsta = true;
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     是否包括开头字符串，默认true
        /// </summary>
        public bool Bend { get; set; }

        /// <summary>
        ///     是否包括开头字符串，默认true
        /// </summary>
        public bool Bsta { get; set; }

        /// <summary>
        ///     结束字符串
        /// </summary>
        public string End { get; set; }

        /// <summary>
        ///     开始字符串
        /// </summary>
        public string Sta { get; set; }

        public string Str { get; private set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     开始截取后的字符串,获取不到的返回空值。
        /// </summary>
        /// <returns>截取后的字符串</returns>
        public string Start()
        {
            var staof = this.Str.IndexOf(this.Sta, StringComparison.Ordinal) + (this.Bsta ? 0 : this.Sta.Length);
            var endof = this.Str.IndexOf(this.End, StringComparison.Ordinal) + (!this.Bend ? 0 : this.End.Length);
            if (staof == -1 || endof == -1)
            {
                return string.Empty;
            }
            var substring = this.Str.Substring(staof, endof - staof);
            return substring;
        }

        #endregion
    }
}